<?php

/**
 * Autocomplete for Jessica Channel
 */
function jessica_sw_autocomplete_api_j_channel($arg) {
  if (empty($arg)) {
      return false;
  }
  $_GET['title'] = check_plain($arg);
  $results = views_get_view_result('jessica_autocomplete', 'master');
  $arr = array();
  foreach ($results as $k => $v) {
    $arr[$v->node_title . " [nid: $v->nid]"] = $v->node_title . " [nid: $v->nid]";
  }
  drupal_json_output($arr);
}
/**
 * Autocomplete for Jessica TV
 */
function jessica_sw_autocomplete_api_j_tv($arg) {
  if (empty($arg)) {
      return false;
  }
  $_GET['title'] = check_plain($arg);
  $results = views_get_view_result('jessica_autocomplete', 'embed_2');
  $arr = array();
  foreach ($results as $k => $v) {
    $arr[$v->node_title . " [nid: $v->nid]"] = $v->node_title . " [nid: $v->nid]";
  }
  drupal_json_output($arr);
}

/**
 * Autocomplete for JTV
 */
function jessica_sw_autocomplete_api_j_jtv($arg) {
  if (empty($arg)) {
      return false;
  }
  $_GET['title'] = check_plain($arg);
  $results = views_get_view_result('jessica_autocomplete', 'embed_1');
  $arr = array();
  foreach ($results as $k => $v) {
    $arr[$v->node_title . " [nid: $v->nid]"] = $v->node_title . " [nid: $v->nid]";
  }
  drupal_json_output($arr);
}
